package com.csun.cmny.provider.web.frontend;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OptSmsService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-09-26 17:40
 * @Description: the class opc aliyun sms
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/aliyun/sms", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OpcAliyunSmsController {

    @Resource
    private OptSmsService optSmsService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @PostMapping(value = "/send")
    public Wrapper sendSms(@RequestBody SendSmsRequest sendSmsRequest) {

        sendSmsRequest.setTemplateParam("{\"code\":\"123456\",\"product\":\"日创科技-守护佳智能看护系统\"}");
        SendSmsResponse sendSmsResponse = optSmsService.sendSms(sendSmsRequest);

        //return WrapMapper.ok(sendSmsResponse);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), sendSmsRequest);
    }


}
